const KoaRouter = require('@koa/router')
const userController = require('../controller/user.controller')
const { verifyUser, handlePassword, verifyUserWithId, verifyUserRole } = require('../middleware/user.middleware')
const { verifyAuth } = require('../middleware/login.middleware')

// 1.创建路由对象
const userRouter = new KoaRouter({ prefix: '/users' })

// 2.1.用户注册接口
userRouter.post('/register', verifyUser, handlePassword, userController.create)

// 2.2.用户信息接口
userRouter.get('/id/:id', verifyAuth, verifyUserWithId, userController.findUser)

// 2.3.获取全部用户接口
userRouter.get('/list', verifyAuth, userController.findUserList)

// 2.4.更新用户信息接口
userRouter.post('/update', verifyAuth, verifyUserRole, userController.updateUser)

// 2.5.删除用户接口
userRouter.post('/delete', verifyAuth, verifyUserRole, userController.deleteUser)

// 3.导出路由
module.exports = userRouter